<template>
	<view class="userLayout pageBg">
		<custom-nav-title :title="title"></custom-nav-title>
		<view class="userInfo">
			<view class="avatar" @click="login">
				<uni-icons type="personadd" size="80" v-if="!avatarUrl"></uni-icons>
				<image :src="avatarUrl" v-if="avatarUrl"></image>
			</view>
			<view class="ip">{{nickName}}</view>
			<!-- <view class="address">{{nickName}}</view> -->
		</view>
		<view class="section">
			<view class="list">
				<!-- <navigator url="/pages/classlist/classlist" class="row">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28b389"></uni-icons>
						<view class="text">我的下载</view>
					</view>
					<view class="right">
						<view class="text">3</view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</navigator>
				<navigator url="/pages/classlist/classlist" class="row">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28b389"></uni-icons>
						<view class="text">我的评分</view>
					</view>
					<view class="right">
						<view class="text">3</view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</navigator> -->
				<view class="row">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28b389"></uni-icons>
						<view class="text">联系客服</view>
					</view>
					<view class="right">
						<view class="text"></view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
					<!-- #ifdef MP -->
					<button open-type="contact">联系客服</button>
					<!-- #endif -->
					<!-- #ifndef APP -->
					<button @click="clickContact">拨打电话</button>
					<!-- #endif -->
				</view>
			</view>
		</view>
		<!-- <view class="section">
			<view class="list">
				<view class="row" v-for="item in 2">
					<view class="left">
						<uni-icons type="download-filled" size="20" color="#28b389"></uni-icons>
						<view class="text">我的下载</view>
					</view>
					<view class="right">
						<view class="text">3</view>
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
			</view>
		</view> -->
	</view>
</template>

<script setup>
import { ref } from 'vue';
import {apiLogin} from '@/api/apis.js'
const avatarUrl = ref("");
const nickName = ref("游客");

const getLoginInfo = async(code,user) => {
	// console.log(user,"微信登录后返回的信息");
	let params = {
		code: code,
		nickName: user.userInfo.nickName,
		avatarUrl: user.userInfo.avatarUrl,
		signature: user.signature,
		rawData: user.rawData,
		encryptedData: user.encryptedData,
		iv: user.iv
	}
	let res = await apiLogin(params);
	// console.log(res.data,"------------------------")
	let admres = res.data;
	if(admres.code === 200){
		uni.setStorageSync("userInfo",user.userInfo)
		mobile(admres);
	}
	return res.data;
}
const doRegister = async(params) => {
	let res = await apiRegister(params);
}
const mobile = (admres) => {
	uni.setStorageSync("token",admres.token)
	if(!admres.phone){
		// 绑定手机号
	}else {
		// 替换用户名，头像
	}
}
const login = () => {
	let _userInfo = uni.getStorageSync("userInfo");
	if(_userInfo) {
		uni.showToast({
			title: '登录成功',
			duration: 1000
		})
	}
	uni.getUserInfo({
		desc: "登录的数据",
		success(user) {
			console.log(user,"返回用户信息");
			avatarUrl.value = user.userInfo.avatarUrl;
			nickName.value = user.userInfo.nickName;
			uni.login({
				provider: 'weixin',
				success(res) {
					// 获取用户信息
					console.log(res,"微信登录后返回的信息");
					getLoginInfo(res.code,user);
				}
			})
		}
	})
}
const clickContact = () =>{
	uni.makePhoneCall({
		phoneNumber: '114' //仅为示例
	});
}
</script>

<style lang="scss" scoped>
.userLayout{
	.userInfo{
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		padding: 50rpx 0;
		.avatar{
			width: 160rpx;
			height: 160rpx;
			border-radius: 50%;
			overflow: hidden;
			image{
				width: 160rpx;
				height: 160rpx;
			}
		}
		.ip{
			font-size: 44rpx;
			color: #333;
			padding: 20rpx 0 5rpx;
		}
		.address{
			font-size: 28rpx;
			color: #aaa;
		}
	}
	.section{
		width: 690rpx;
		margin: 50rpx auto;
		border: 1px solid #eee;
		border-radius: 10rpx;
		box-shadow: 0 0 30rpx rgba(0, 0, 0, .5);
		.list{
			.row{
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 30rpx;
				height: 100rpx;
				border-bottom: 1px solid #eee;
				background: white;
				position: relative;
				&:last-child{border-bottom: 0;}
				.left{
					display: flex;
					align-items: center;
					.text{
						padding-left: 20rpx;
						color: #666;
					}
				}
				.right{
					display: flex;
					align-items: center;
					.text{
						font-size: 28rpx;
						color: #aaa;
					}
				}
				button{
					position: absolute;
					top: 0;
					left: 0;
					height: 100rpx;
					width: 100%;
					opacity: 0;
				}
			}
		}
		
	}
}	       
</style>
